all: install

install: install-bashrc install-vimrc install-gitconfig

install-bashrc:
	@if [ ! -f ~/.bash.user ]; then \
		cp -v ./bash.user ~/.bash.user; \
	elif ! diff ./bash.user ~/.bash.user > .tmp.diff ; then \
		echo "diff ./bash.user ~/.bash.user";\
		cat .tmp.diff;\
		echo -n "continue ? [y/n]"; \
		read SELECTION; \
		[ "$${SELECTION}" = "y" ] && cp -v ./bash.user ~/.bash.user; \
	fi;
	@rm .tmp.diff;
	@if ! grep "\. \~\/\.bash\.user" ~/.bashrc >/dev/null; then \
		echo 'appending reference of ~/.bash.user to ~/.bashrc';\
		echo 'if [ -f ~/.bash.user ]; then' >> ~/.bashrc;\
		echo '    . ~/.bash.user' >> ~/.bashrc;\
		echo 'fi' >>~/.bashrc;\
	fi

install-vimrc:
	@if [ ! -f ~/.vimrc ]; then\
		cp -v vimrc ~/.vimrc;\
	elif ! diff ./vimrc ~/.vimrc > .tmp.diff; then\
		echo "diff ./vimrc ~/.vimrc";\
		cat .tmp.diff;\
		echo -n "continue ? [y/n]";\
		read SELECTION;\
		[ "$${SELECTION}" = "y" ] && cp -v vimrc ~/.vimrc;\
	fi;
	@rm .tmp.diff;
	@if [ ! -d ~/.vim/bundle/Vundle.vim ]; then \
		git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim; \
		vim +PluginInstall +qall; \
	fi

install-gitconfig:
	@if [ ! -f ~/.gitconfig ]; then\
		cp -v gitconfig ~/.gitconfig;\
	elif ! diff ./gitconfig ~/.gitconfig > .tmp.diff; then\
		echo "diff ./gitconfig ~/.gitconfig";\
		cat .tmp.diff; rm .tmp.diff;\
		echo -n "continue ? [y/n]";\
		read SELECTION;\
		[ "$${SELECTION}" = "y" ] && cp -v gitconfig ~/.gitconfig;\
	fi;
	@rm .tmp.diff;


upload:
	@cp -v ~/.vimrc vimrc
	@cp -v ~/.bash.user bash.user
	@cp -v ~/.gitconfig gitconfig

status:
	@diff vimrc ~/.vimrc > .temp.log; \
	diff bash.user ~/.bash.user >> .temp.log; \
	diff gitconfig ~/.gitconfig >> .temp.log; \
	less .temp.log; \
	rm -rf .temp.log

.PHONY: install install-bashrc install-vimrc install-gitconfig upload status all
